package com.ddx.service.impl;

import com.ddx.common.exception.ResultModel;
import com.ddx.dao.CompanyMapper;
import com.ddx.dto.CompanyDto;
import com.ddx.enums.SmsCodeEnum;
import com.ddx.pojo.Company;
import com.ddx.service.CompanyService;
import com.ddx.service.ICommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: liyuxiang
 * @create: 2019-01-06
 */
@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    ICommonService commonService;

    @Autowired
    CompanyMapper companyMapper;

    @Override
    public ResultModel register(int userId, CompanyDto companyDto) {
        commonService.verifiSmsCode(companyDto.getSmsCode(), companyDto.getOpsMobile(), SmsCodeEnum.REGISTER_COMPANY.getValue());
        Company company = new Company();
        company.setUserId(userId);
        company.setName(companyDto.getName());
        company.setAudit(0);
        company.setImage(companyDto.getImage());
        company.setType(companyDto.getType());
        company.setBusinessLicenseImage(companyDto.getBusinessLicenseImage());
        company.setCautionMoney(0);
        company.setCompanyName(companyDto.getCompanyName());
        company.setDescription(companyDto.getDescription());
        company.setOpsCardId(companyDto.getOpsCardId());
        company.setOpsName(companyDto.getOpsName());
        company.setOpsMobile(companyDto.getOpsMobile());
        company.setOfficialLetterImage(companyDto.getOfficialLetterImage());
        company.setOtherImage(companyDto.getOtherImage());
        companyMapper.insert(company);
        return ResultModel.getSuccessInstance();
    }
}
